package com.qf.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *   spring-context.xml
 *     <bean id
 *
 *    Java  配置类
 *
 *    RabbitMq的交换机及队列  并绑定
 * @author lixu
 */
@Configuration
public class RabbitMqConfig {


    public static final String EXCHANGE_NAME = "boot-topic-exchange";
    public static final String QUEUE_NAME = "boot-queue";//Shift + Ctrl + u
    public static final String ROUTING_KEY = "boot-routing-key";

    /**
     * 创建交换机
     */
    @Bean
    public Exchange bootExchange(){
        //return new FanoutExchange(EXCHANGE_NAME);
        return ExchangeBuilder.directExchange(EXCHANGE_NAME).build();
    }

    /**
     * 队列
     */
    @Bean
    public Queue bootQueue(){
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

/*    @Autowired
    @Qualifier(value = "bootExchange")
    private Exchange bootExchange;
    @Autowired
    @Qualifier(value = "bootQueue")
    private Queue bootQueue;*/
    /**
     * 绑定
     */
    @Bean
    public Binding bindingBootQueueToBootExchange(Exchange bootExchange,Queue bootQueue){
        return BindingBuilder.bind(bootQueue).to(bootExchange).with(ROUTING_KEY).noargs();
    }

}
